#pragma once
/******************************/
/*    						  */
/*	生成coff目标文件				*/
/*	生成节表结构定义		  	  */
/******************************/

#include<Windows.h>

#define CST_FUNC 0x20
#define CST_NOTFUNC 0



/*	改进后的COFF 符号表	*/

typedef struct CoffSym
{
	DWORD Name;
	DWORD Next;
	DWORD Value;
	short SectionNumber;
	WORD Type;
	BYTE StorageClass;
	BYTE NumberOfAuxSymbols;
}CoffSym;



/*	改进后的COFF重定位信息	*/

typedef struct CoffReloc
{
	DWORD offset;
	DWORD cfsym;
	BYTE section;
	BYTE type;
}CoffReloc;



/*	节结构定义	*/

typedef struct Section
{
	int data_offset;		//当前数据偏移位置
	char *data;				//节数据
	int data_allocated;		//分配内存空间
	char index;				//节序号
	struct Section *link;	//关联的其他节，符号节关联字符串节
	int *hashtab;			//哈希表，只用于存储符号表
	IMAGE_SECTION_HEADER sh;
};	


Section *section_new(char *name, int Characteristics); 
void *section_ptr_add(Section *sec, int increment);
void section_realloc(Section *sec, int new_size);
Section *new_coffsym_section(char *symtab_name, int Characteristics, char *strtab_name);
int coffsym_add(Section *symtab, char *name, int val, int sec_index, short type, char StorageClass);
void coffsym_add_update(Symbol *s, int val, int sec_index, short type, char StorageClass);
char *coffstr_add(Section *strtab, char *name);
int coffsym_search(Section *symtab, char *name);
void coffreloc_add(Section *sec, Symbol *sym, int offset, char type);
void coffreloc_direct_add(int offset, int cfsym, char section, char type);
void init_coff();
void free_sections();
void write_obj(char *name);
void fpad(FILE *fp, int new_pos);
